.SUFFIXES: .c .o .lo

COMPILE = $(CC) $(CFLAGS)
INC_PATH = -I../common -I/usr/include/fastcommon -I/usr/local/include
LIB_PATH = -L/usr/local/lib -lfastcommon $(LIBS)
TARGET_PATH = $(TARGET_PREFIX)/bin
CONFIG_PATH = $(TARGET_CONF_PATH)
TARGET_LIB = $(TARGET_PREFIX)/lib
TARGET_INC = $(TARGET_PREFIX)/include

STATIC_OBJS = ../common/fdht_global.o ../common/fdht_proto.o \
              ../common/fdht_func.o fdht_client.o

FDHT_SHARED_OBJS = ../common/fdht_global.lo ../common/fdht_proto.lo \
                   ../common/fdht_func.lo fdht_client.lo

FDHT_HEADER_FILES = ../common/fdht_define.h  ../common/fdht_func.h  \
                    ../common/fdht_global.h  ../common/fdht_proto.h \
                    ../common/fdht_proto_types.h ../common/fdht_types.h \
                    fdht_client.h

ALL_OBJS = $(STATIC_OBJS) $(FDHT_SHARED_OBJS)

ALL_PRGS = fdht_test fdht_batch_test fdht_test_thread fdht_test_set \
           fdht_test_get fdht_set fdht_get fdht_delete
ALL_LIBS = libfdhtclient.so.1

all: $(ALL_OBJS) $(ALL_PRGS) $(ALL_LIBS)
libfdhtclient.so.1:
	$(COMPILE) -o $@ $< -shared $(FDHT_SHARED_OBJS) $(LIB_PATH) -L. -lfastcommon
	ln -fs libfdhtclient.so.1 libfdhtclient.so
.o:
	$(COMPILE) -o $@ $<  $(STATIC_OBJS) $(LIB_PATH) $(INC_PATH)
.c:
	$(COMPILE) -o $@ $<  $(STATIC_OBJS) $(LIB_PATH) $(INC_PATH)
.c.o:
	$(COMPILE) -c -o $@ $<  $(INC_PATH)
.c.lo:
	$(COMPILE) -c -fPIC -o $@ $<  $(INC_PATH)
install:
	mkdir -p $(TARGET_PATH)
	mkdir -p $(CONFIG_PATH)
	mkdir -p $(TARGET_LIB)
	cp -f $(ALL_PRGS) $(TARGET_PATH)
	cp -f $(ALL_LIBS) $(TARGET_LIB)
	if [ ! -f $(CONFIG_PATH)/fdht_client.conf ]; then cp -f ../conf/fdht_client.conf ../conf/fdht_servers.conf $(CONFIG_PATH); fi

	mkdir -p $(TARGET_INC)
	mkdir -p $(TARGET_INC)/fastdht
	cp -f $(FDHT_HEADER_FILES) $(TARGET_INC)/fastdht

	ln -fs $(TARGET_LIB)/libfdhtclient.so.1 $(TARGET_LIB)/libfdhtclient.so
	ln -fs $(TARGET_LIB)/libfdhtclient.so.1 /usr/lib/libfdhtclient.so
clean:
	rm -f $(ALL_OBJS) $(ALL_PRGS) $(ALL_LIBS)

